let Controller = {
  mounted() {
    this.initData();
  },
  activated() {
    this.initData();
    this.requestDetail();
  },
  methods: {
    initData() {
      const param = this.$route.query.data;
      this.Model.queryData = _.cloneDeep(param);
      this.$set(this.Model.path, 3, {
        label: '列表详情',
        name: 'purchaseWarehousingDetail',
        query: {
          data: param
        }
      })
    },
    requestDetail() {
      const batchNo = this.Model.queryData.batchNo;
      const param = {
          batchNo
      }
      if (batchNo) this.$ajax
        .post(this.apiTest + `/sale/saleGoodsInfo/getByBarCode`, param)
        // .post(this.apiTest + `/sale/saleGoodsInfo/getByBarCode`, param)
        .then(response => {
          const data = response.data;
          if(data.status == 200){
            const result = data.result;
            this.Model.saleGoodsInfo = [result.saleGoodsInfo];//商品属性信息
            this.Model.workFee = [result.workFee];//工费信息
            this.Model.checkData = [result.checkData];//国检信息
            this.Model.qcData = [result.qcData];//质检信息
          }else{
            this.$message.error(data.msg)
          }
        })
        .catch(error => {
          this.$message.error('请求错误');
        });
    },
    toBarcodeDetail() {
      //跳转条码详情
      const name = 'purchaseWarehousingDetail';
      this.$router.push({
        name: name,
        query: {
          data: row
        }
      })
    },
    setStepData(list, status) {
      let activeStep = 0,
        step = [];
      for (let i = 0; i < list.length; i++) {
        if (list[i].code == status) activeStep = i;
        step.push({
          title: list[i].codeName,
          description: list[i].createTime
        })
      };
      this.Model.stepOption = {
        activeStep,
        step
      }
    },

    onDeleteExportData() {
      const list = this.Model.exportTableSelectList.map(item => {
        return item.id
      });
      console.log(list)
    },
    onTableSelectionChange(val) {
      this.Model.exportTableSelectList = val;
      console.log(this.Model.exportTableSelectList);
    },
    cardClick(color) {
      this.Model.cardSelected = color;
    },
    showChild(val) {
      this.Model.searchFromData = val;
    },
    toSearch(val) {
      console.log(val)
    },
    toClear(val) {
      this.Model.searchFromData = this.Model.defaultSearchFromData;
    },
    toExport(val) {
      console.log(val);
    },
    onTabChange(val) {
      switch (val) {
        case 1:
          break;
        case 2:
          break;
        case 3:
          break;
      }
    },
    toggleTableDetail(val) {
      const obj = this.Model[val];
      if (obj.flag === true) {
        this.Model[val].src = require('@/assets/img/icon_collapse.png');
        this.Model[val].flag = false;
      } else {
        this.Model[val].src = require('@/assets/img/icon_unfold.png');
        this.Model[val].flag = true;
      }
    },
    onDialogEdit(flag, val) {
      this.Model.editDialogFlag = flag;
      if (flag === false) return;
      const obj = this.Model[val];
      this.Model.editDialogFormData = _.cloneDeep(this.Model.defaultEditDialogFormData);
      this.getAddress();
    },
    changeAddress(val) {
      if (!val) {
        this.getAddress();
      }
    },
    getAddress() {
      const idcard = 4310555;
      this.$ajax.post(this.apiTest + `/sale/saleOrder/getAddressByIdCard/${idcard}`, {})
        .then(response => {
          const data = response.data;
          if (data.status == 200) {
            this.Model.addressList = data.result;
          }
        }).catch(err => {
          console.log(err)
        })
    },
    updateBaseSaleOrder() {
      const data = this.Model.editDialogFormData;
      let params;
      if (data.shippingMethod === '1') {
        params = {
          shippingMethod: data.shippingMethod,
          shipper: data.shipper,
          originChannel: data.originChannel,
          salesman: data.salesman,
        }
      } else {
        params = data;
      }
      this.$ajax.post(this.apiTest + `/sale/saleOrder/updateBaseSaleOrder`, params)
        .then(response => {
          const data = response.data;
          if (data.status == 200) {
            this.onDialogEdit(false);
            this.$message({
              type: 'success',
              message: '已成功保存'
            });
            this.requestDetail();
          } else {
            this.$message.error(data.msg);
          }
        }).catch(err => {
          this.$message.error(err);
          this.onDialogEdit(false);
        });
    },
  }
}
export default Controller;
